package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TExamPackage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TExamItem;
import com.ruoyi.system.service.ITExamItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 体检项目明细Controller
 *
 * @author ruoyi
 * @date 2025-06-27
 */
@RestController
@RequestMapping("/system/item")
public class TExamItemController extends BaseController {
    @Autowired
    private ITExamItemService tExamItemService;

    /**
     * 查询体检项目明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(TExamItem tExamItem) {
        startPage();
        List<TExamItem> list = tExamItemService.selectTExamItemList(tExamItem);
        return getDataTable(list);
    }

    /**
     * 导出体检项目明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:export')")
    @Log(title = "体检项目明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TExamItem tExamItem) {
        List<TExamItem> list = tExamItemService.selectTExamItemList(tExamItem);
        ExcelUtil<TExamItem> util = new ExcelUtil<TExamItem>(TExamItem.class);
        util.exportExcel(response, list, "体检项目明细数据");
    }

    /**
     * 获取体检项目明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tExamItemService.selectTExamItemById(id));
    }

    /**
     * 新增体检项目明细
     */
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "体检项目明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TExamItem tExamItem) {
        return toAjax(tExamItemService.insertTExamItem(tExamItem));
    }

    /**
     * 修改体检项目明细
     */
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "体检项目明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TExamItem tExamItem) {
        return toAjax(tExamItemService.updateTExamItem(tExamItem));
    }

    /**
     * 删除体检项目明细
     */
    @PreAuthorize("@ss.hasPermi('system:item:remove')")
    @Log(title = "体检项目明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tExamItemService.deleteTExamItemByIds(ids));
    }

    //根据项目名称找价格
    @GetMapping("/price/getPriceByName")
    public Double getPriceByName(@RequestParam String name) {
        return tExamItemService.getPriceByName(name);
    }

    //根据项目名称中查找所有包含项目的套餐
    @GetMapping("/getPackageByName")
    public List<TExamPackage> getPackageByName(@RequestParam String name) {
        return tExamItemService.getPackageByName(name);
    }
}
